package dongwu;

	 import java.io.*;
	import java.util.*;

	public class chaxun{
	    static private Map<String, String > dict= new HashMap();
	    static private int size;

	    public static int getSize(){return size;}

	    public static void insertPare(String EN, String CN){
	        dict.put(EN, CN);
	        size ++;
	    }

	    public static void flushToFile() throws IOException{

	        File file = new File("dict.dat");
	        FileOutputStream fop = new FileOutputStream(file);
	        ObjectOutputStream oos = new ObjectOutputStream(fop);

	        oos.writeObject(dict);

	        oos.flush();
	        oos.close();
	        fop.close();
	    }

	    public static Map<String, String> getFromFile(String fileName)
	                            throws IOException, ClassNotFoundException{

	        FileInputStream fis = new FileInputStream(fileName);
	        ObjectInputStream ois = new ObjectInputStream(fis);

	        Map<String, String> dict = (Map<String, String>) ois.readObject();

	        fis.close();
	        ois.close();

	        return dict;
	    }

	    public static String query(String EN)
	            throws IOException, ClassNotFoundException{

	        Map<String, String> map = getFromFile("dict.dat");
	        return map.get(EN);
	    }

	    public static void main(String[] args){
	        insertPare("rabbit", "兔子");
	        insertPare("dog","狗");
	        insertPare("cat","猫");
	        try {
	            flushToFile();

	            System.out.print("查询: ");
	            Scanner scanner = new Scanner(System.in);
	            String read = scanner.nextLine();

	            System.out.println(query(read));
	        }catch (Exception e){}

	    }
	}

